﻿using Creator.Core.Log;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace DesktopCreator
{
    /// <summary>
    /// LogWindow.xaml 的交互逻辑
    /// </summary>
    public partial class LogWindow : Window
    {
        private static LogWindow logInstance;
        internal LogDB log = new LogDB();
        private LogWindow()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 只能通过单例访问
        /// </summary>
        public static LogWindow LogInstance
        {
            get
            {
                if(logInstance == null)
                {
                    logInstance = new LogWindow();
                }
                return logInstance;
            }
        }

        public void ShowMsg(string msg,LogLevel level = LogLevel.Information)
        {
            TextBlock tb = new TextBlock()
            {
                Text = $"[{level}]{DateTime.Now:yyyy-mm-dd HH:MM:ss}:{msg}",
            };
            listInfo.Items.Add(tb);
            log.AddLog(msg,level);
        }
    }
}
